﻿<visi:VisiPage x:Class="VNet.VisiSuite.VisiCentral.Views.MainView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:visi="clr-namespace:VNet.VisiSuite.VisiCentral.Controls"
        xmlns:vm="clr-namespace:VNet.VisiSuite.VisiCentral.ViewModels"
        xmlns:c="clr-namespace:VNet.VisiSuite.VisiCentral.Controls"
        xmlns:vuc="clr-namespace:VNet.VisiSuite.Controls;assembly=VNet.VisiSuite.Controls"
        xmlns:converter="clr-namespace:VNet.VisiSuite.VisiCentral.Common.Converters"
        xmlns:helper="clr-namespace:VNet.VisiSuite.VisiCentral.Common.Helpers"
        xmlns:dg="http://infragistics.com/DataPresenter"
        xmlns:igDock="http://infragistics.com/DockManager"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        DataContext="{DynamicResource MainViewModel}" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
    
    <visi:VisiPage.Resources>
        <ResourceDictionary >
            <vm:MainViewModel x:Key="MainViewModel" />

            <Style TargetType="Button" x:Key="TransparentButton">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border Background="Transparent">
                                <ContentPresenter/>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <vuc:MultiValueColorConverter x:Key="colorConverter" />

            <DataTemplate x:Key="CellButton" DataType="{x:Type vm:CellViewModel}">
                <Button x:Name="_cell_button" Style="{StaticResource TransparentButton}"  BorderThickness="0" BorderBrush="{x:Null}"  Background="{x:Null}"  Click="cellClicked"
                        Visibility="{Binding Path=Hide}" Margin="0,0,1,5">
                    <Button.Tag>
                        <sys:Double>1.0</sys:Double>
                    </Button.Tag>
                    <Border Background="{Binding BackgroundColor}" BorderThickness="0" CornerRadius="20,20,0,0">
                        <Grid Margin="0,0,0,0">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="26*"/>
                                <RowDefinition Height="28*"/>
                                <RowDefinition Height="22*"/>
                            </Grid.RowDefinitions>
                            <Viewbox Grid.Row="0" Margin="0,2,0,-6" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center">
                                <Grid x:Name="gridBigLed">
                                    <Border x:Name="border1" BorderThickness="2"
                                            Width="24" Height="24" CornerRadius="12">
                                        <Border.Background>
                                            <RadialGradientBrush GradientOrigin="0.332,0.222">
                                                <GradientStop Color="#FFE4E4E4"/>
                                                <GradientStop Offset="0.95">
                                                    <GradientStop.Color>
                                                        <MultiBinding Converter="{StaticResource colorConverter}">
                                                            <Binding Path="RollupColor"/>
                                                            <Binding Path="Tag" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=Button}"/>
                                                        </MultiBinding>
                                                    </GradientStop.Color>
                                                </GradientStop>
                                            </RadialGradientBrush>
                                        </Border.Background>
                                        <Border.BorderBrush>
                                            <RadialGradientBrush>
                                                <GradientStop Color="#FF020202" Offset="0.383"/>
                                                <GradientStop Color="#FFE4E4E4" Offset="1"/>
                                            </RadialGradientBrush>
                                        </Border.BorderBrush>
                                    </Border>
                                </Grid>
                            </Viewbox>
                            <Viewbox Grid.Row="1" Stretch="Uniform" Margin="-2,-2,-2,-9">
                                <TextBox Text="{Binding Path=DisplayName, Mode=OneWay}" IsHitTestVisible="False" FontFamily="Segoe UI" FontWeight="SemiBold" Foreground="{Binding DisplayNameFontColor}"  HorizontalAlignment="Center" VerticalAlignment="Center" BorderBrush="{x:Null}" Background="{x:Null}" />
                            </Viewbox>
                            <Border Grid.Row="2" Margin="2,0,2,2" Background="{Binding AlarmColor}" BorderThickness="0">
                                <Viewbox Stretch="Uniform" Margin="-2,-3,-2,-3">
                                    <TextBox Text="{Binding Path=Percent}" IsHitTestVisible="False" FontFamily="Segoe UI" FontWeight="SemiBold" Foreground="{Binding AlarmFontColor}" HorizontalAlignment="Center" VerticalAlignment="Center" BorderBrush="{x:Null}" Background="{x:Null}"/>
                                </Viewbox>
                            </Border>
                        </Grid>
                    </Border>
                </Button>
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding Flash}" Value="True">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard Name="highlight">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="_cell_button" Storyboard.TargetProperty="Tag" From="1" To="0" Duration="0:0:0.5" AutoReverse="True" RepeatBehavior="Forever"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                        <DataTrigger.ExitActions>
                            <StopStoryboard BeginStoryboardName="highlight"/>
                        </DataTrigger.ExitActions>
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>

        </ResourceDictionary>
    </visi:VisiPage.Resources>
    
    <vuc:BusyIndicator IsBusy="{Binding IsBusy}">
        <Grid Focusable="False" Background="#FF181818" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="42" />
            </Grid.RowDefinitions>
            
            <!--
            <ig:ThemeManager.Theme>
                <ig:MetroDarkTheme />
            </ig:ThemeManager.Theme>
            -->

            <!--Header-->
            <c:Header2Control Grid.Row="0" Title="{Binding PageTitle}" ShiftDate="{Binding ShiftDate, Mode=TwoWay}" 
                              ShiftList="{Binding ShiftList}" Shift="{Binding SelectedAreaShift, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                              NextShiftCommand="{Binding NextShiftCommand}"
                              PreviousShiftCommand="{Binding PreviousShiftCommand}"/>

            <!--Body-->
            <Grid Grid.Row="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="1*" />
                    <RowDefinition Height="1*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <!-- Background="{x:Null}" -->
                <vuc:AspectRatioLayoutDecorator AspectRatio="0.95" Grid.Row="1" Grid.Column="0"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,4,0,0">
                    <ItemsControl x:Name="_cell_layout1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ItemsSource="{Binding CellGroup1}"
                                  ItemTemplate="{DynamicResource CellButton}" BorderThickness="0" BorderBrush="#FF3c3c3c" Padding="4,4,4,0">
                        <ItemsControl.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FF434749" Offset="0"/>
                                <GradientStop Color="#FF1E252A" Offset="1"/>
                            </LinearGradientBrush>
                        </ItemsControl.Background>
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <UniformGrid Columns="10" HorizontalAlignment="Stretch" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </vuc:AspectRatioLayoutDecorator>

                <vuc:AspectRatioLayoutDecorator AspectRatio="0.95" Grid.Row="0" Grid.Column="0"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,0,0,4">
                    <ItemsControl x:Name="_cell_layout2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ItemsSource="{Binding CellGroup2}"
                                  ItemTemplate="{DynamicResource CellButton}" BorderThickness="0" BorderBrush="#FF3c3c3c" Padding="4,4,4,0">
                        <ItemsControl.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FF656565" Offset="0"/>
                                <GradientStop Color="#FF434749" Offset="1"/>
                            </LinearGradientBrush>
                        </ItemsControl.Background>
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <UniformGrid Columns="10" HorizontalAlignment="Stretch" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </vuc:AspectRatioLayoutDecorator>

                <vuc:AspectRatioLayoutDecorator AspectRatio="0.855" Grid.Row="0" Grid.Column="1"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="8,0,0,4">
                    <ItemsControl x:Name="_cell_layout3" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ItemsSource="{Binding CellGroup3}"
                                  ItemTemplate="{DynamicResource CellButton}" BorderThickness="0" BorderBrush="#FF3c3c3c" Padding="4,4,4,0">
                        <ItemsControl.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FF656565" Offset="0"/>
                                <GradientStop Color="#FF434749" Offset="1"/>
                            </LinearGradientBrush>
                        </ItemsControl.Background>
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <UniformGrid Columns="9" HorizontalAlignment="Stretch" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </vuc:AspectRatioLayoutDecorator>


                <Border Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Background="White" BorderThickness="0" Margin="8,4,10,0" Padding="0,0,10,0" Visibility="{Binding ShowCellProductionControls}" >
                    <!--
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF434749" Offset="0"/>
                            <GradientStop Color="#FF1E252A" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    -->
                    <vuc:ProductionControl x:Name="_production" Margin="-8,-6,0,0" Visibility="{Binding ShowCellProductionControls}" />
                </Border>

                <Border Grid.Row="0" Grid.Column="2" BorderThickness="0" Margin="8,0,10,4" Padding="0,0,10,0" Visibility="{Binding ShowCellProductionControls}" >
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF656565" Offset="0"/>
                            <GradientStop Color="#FF434749" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <vuc:DowntimeGraphControl Title="{Binding CellDowntimeGraphTitle}" TitleFontColor="Yellow"  GraphData="{Binding CellDowntimeGraphData}" />
                </Border>

                <Border Grid.Row="0" Grid.Column="2" Margin="8,0,10,4" Padding="0,0,10,0" Visibility="{Binding ShowAreaProductionControls}" >
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF656565" Offset="0"/>
                            <GradientStop Color="#FF434749" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <vuc:UtilizationGraphControl GraphData="{Binding AreaUtilizationGraphData}" />
                </Border>

                <Border Grid.Row="1" Grid.Column="1" BorderThickness="0" Margin="8,4,0,0" Visibility="{Binding ShowAreaProductionControls}" >
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF434749" Offset="0"/>
                            <GradientStop Color="#FF1E252A" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <vuc:PlantMetrics  PlantMetricsData="{Binding AreaPlantMetricsData}" Legend="{Binding GraphLegend}"/>
                </Border>
                
                <Border Grid.Row="1" Grid.Column="2" Margin="8,4,10,0" Padding="0,0,10,0" Visibility="{Binding ShowAreaProductionControls}" >
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF434749" Offset="0"/>
                            <GradientStop Color="#FF1E252A" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <vuc:DowntimeGraphControl Title="{Binding AreaDowntimeGraphTitle}" GraphData="{Binding AreaDowntimeGraphData}" TitleFontColor="Yellow" />
                </Border>


            </Grid>
            
            <!--Footer-->
            <Border Grid.Row="2" Background="White" BorderBrush="#FF181818" BorderThickness="10,8,10,0">
                <ContentControl Template="{StaticResource FooterTemplate}" Background="White" />
            </Border>

        </Grid>
    </vuc:BusyIndicator>
</visi:VisiPage>
